<template>
  <div
    v-if="visible && questions.length > 0"
    class="suggested-questions-float"
    :class="{ 'animate-slide-up': visible }"
  >
    <div class="questions-container">
      <div class="questions-header">
        <span class="header-icon">💡</span>
        <span class="header-text">试着问问</span>
        <button class="close-btn" @click="handleClose" title="关闭">
          <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="2"
              d="M6 18L18 6M6 6l12 12"
            />
          </svg>
        </button>
      </div>

      <div class="questions-list">
        <button
          v-for="(question, index) in questions"
          :key="index"
          class="question-btn"
          @click="handleQuestionClick(question)"
          :title="question"
        >
          <span class="question-text">{{ question }}</span>
          <svg class="question-icon w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
            <path
              stroke-linecap="round"
              stroke-linejoin="round"
              stroke-width="2"
              d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"
            />
          </svg>
        </button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { watch } from 'vue'

interface Props {
  questions: string[]
  visible: boolean
  loading?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  loading: false
})

const emit = defineEmits<{
  'question-click': [question: string]
  close: []
}>()

const handleQuestionClick = (question: string) => {
  console.log('点击建议问题:', question)
  emit('question-click', question)
}

const handleClose = () => {
  emit('close')
}

// 监听visible变化，添加动画效果
watch(
  () => props.visible,
  (newVisible) => {
    if (newVisible) {
      console.log('显示建议问题:', props.questions)
    }
  }
)
</script>

<style scoped>
.suggested-questions-float {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  max-width: 90vw;
  width: 600px;
}

.questions-container {
  background: white;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;
  backdrop-filter: blur(10px);
}

.questions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.header-icon {
  font-size: 16px;
  margin-right: 8px;
}

.header-text {
  font-weight: 600;
  font-size: 14px;
  flex: 1;
}

.close-btn {
  padding: 4px;
  border-radius: 6px;
  transition: all 0.2s ease;
  color: white;
  opacity: 0.8;
}

.close-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.questions-list {
  padding: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.question-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 16px;
  margin-bottom: 6px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  text-align: left;
  transition: all 0.2s ease;
  cursor: pointer;
  group: true;
}

.question-btn:last-child {
  margin-bottom: 0;
}

.question-btn:hover {
  background: #e2e8f0;
  border-color: #cbd5e0;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.question-btn:active {
  transform: translateY(0);
}

.question-text {
  flex: 1;
  font-size: 14px;
  color: #374151;
  line-height: 1.4;
  margin-right: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.question-icon {
  flex-shrink: 0;
  color: #6b7280;
  opacity: 0;
  transition: all 0.2s ease;
}

.question-btn:hover .question-icon {
  opacity: 1;
  color: #4f46e5;
}

/* 动画效果 */
.animate-slide-up {
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* 滚动条样式 */
.questions-list::-webkit-scrollbar {
  width: 4px;
}

.questions-list::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 2px;
}

.questions-list::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 2px;
}

.questions-list::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .suggested-questions-float {
    bottom: 70px;
    width: 95vw;
    max-width: 95vw;
  }

  .questions-container {
    border-radius: 12px;
  }

  .questions-header {
    padding: 10px 12px;
  }

  .header-text {
    font-size: 13px;
  }

  .question-btn {
    padding: 10px 12px;
    border-radius: 8px;
  }

  .question-text {
    font-size: 13px;
  }
}
</style>
